<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>分类管理</title>
</head>

<body>
<div>
<p><a href="adminclass.php">分类管理</a>
  | <a href="artlist.php">文章列表 | </a><a href="addart.php">添加文章</a></p>
</div>
<div>
<form name="addclass" action="addclass.php" method="post">
    <th>添加分类</th>
	<input name="addclass" type="text" />
    <input name="添加分类" type="submit" id="添加分类" value="提交" />
    
</form>
</div>
<div>
<div>文章分类管理</div>
<?php
session_start();
require_once("conn.php");
if(isset($_GET['page']))     //由GET方法获得页面传入当前页数的参数
{
    $page = $_GET['page'];
}
else
{
    $page = 1;
}
$page_size = 8;              //每页显示8条数据
//获取数据总量
$sql = 'select * from artclass';
$result = mysql_query($sql);
$total = mysql_num_rows($result);
//开始计算总页数
if($total)
{
    //如果总数据量小于$page_size，那么只有一页
    if($total < $page_size)
        $page_count = 1;
    //如果有余数，则总页数等于总记录数除以页数的结果取整再加1
    if($total % $page_size)
    {
        $page_count = (int)($total/$page_size) + 1;
    }
    //如果没有余数，则页数等于总数据量除以每页数的结果
    else
    {
        $page_count = $total/$page_size;
    }
}
else
{
    $page_count = 0;
}
//翻页链接
$turn_page = '';
if($page == 1)
{
    $turn_page .= '首页 | 上一页 |';
}
else
{
    $turn_page .= '<a href=adminclass.php?page=1> 首页</a> | <a href=adminclass.php?page='.($page-1).'> 上一页 </a> |';
}
if($page == $page_count || $page_count == 0)
{
    $turn_page .= ' 下一页 | 尾页';
}
else
{
    $turn_page .= '<a href=adminclass.php?page='.($page+1).'> 下一页 </a>|<a href=adminclass.php?page='.$page_count.'> 尾页 </a>';
}

$sql = 'select cs_id,cs_name,artnum,bdata from artclass limit '. ($page-1)*$page_size .', '.$page_size;
$result = mysql_query($sql) OR die("<br/>ERROR: <b>".mysql_error()."</b><br/>产生问题的SQL：".$sql);
?>

<table width="75%" border="0" cellpadding="0" cellspacing="1" bgcolor="#7B7B84">
    <tr bgcolor="#8BBCC7"> 
        <td height="33"><div align="center"><strong>分类编号</strong></div></td>
        <td><div align="center"><strong>分类名称</strong></div></td>
        <td><div align="center"><strong>文章总数</strong></div></td>
        <td><div align="center"><strong>创建时间</strong></div></td>
        <td><div align="center"><strong>操作</strong></div></td>
    </tr>
<?php
if($num = mysql_num_rows($result))
{
    while($row = mysql_fetch_array($result,MYSQL_ASSOC))
    {
?>
    <tr bgcolor="#FFFFFF"> 
        <td height="22" align="right"><?php echo $row['cs_id']; ?>&nbsp;</td>
        <td height="22">&nbsp;<?php echo $row['cs_name']; ?>&nbsp;</td>
        <td height="22">&nbsp;<?php echo $row['artnum']; ?>&nbsp;</td>
        <td height="22">&nbsp;<?php echo $row['bdata']; ?>&nbsp;</td>
        <td height="22">&nbsp;<?php echo " <a href=editclass.php?cs_id=". $row['cs_id'] .">编辑</a>  <a href=delclass.php?cs_id=". $row['cs_id'] .">删除</a>"; ?>&nbsp;</td>
    </tr>
<?php
    }
}
echo $turn_page.'<br/><br/>';
?>
</table>
</div>
</body>
</html>